package com.jzcn.service.impl;

import com.jzcn.common.base.BaseServiceImpl;
import com.jzcn.common.dto.system.tool.ToolCategoryRecordDTO;
import com.jzcn.common.exceptions.BusinessException;
import com.jzcn.common.utils.BeanUtils;
import com.jzcn.domain.AppToolCategory;
import com.jzcn.mapper.AppToolCategoryMapper;
import com.jzcn.service.AppToolCategoryService;
import com.jzcn.service.AppToolService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppToolCategoryServiceImpl extends BaseServiceImpl<AppToolCategoryMapper, AppToolCategory> implements AppToolCategoryService {

    @Resource
    AppToolService appToolService;

    @Override
    public List<ToolCategoryRecordDTO> listData() {
        List<AppToolCategory> appToolCategoryData= super.list();
        return BeanUtils.convertList(appToolCategoryData, ToolCategoryRecordDTO.class);
    }

    @Override
    public Boolean create(ToolCategoryRecordDTO dto) {
        AppToolCategory appToolCategory = new AppToolCategory();
        BeanUtils.copyProperties(dto,appToolCategory);
        return super.save(appToolCategory);
    }

    @Override
    public Boolean update(ToolCategoryRecordDTO dto) {
        AppToolCategory appToolCategory = new AppToolCategory();
        BeanUtils.copyProperties(dto,appToolCategory);
        return super.update(appToolCategory);
    }

    @Override
    public boolean delete(Integer id) {
        if(appToolService.finByCategoryIdCount(id) > 0){
            throw new BusinessException("请删除关联数据");
        }
        return super.remove(id);
    }
}
